package com.ant.collect.controller;


import com.ant.collect.common.ResultVo;
import com.ant.collect.dto.CompanyDto;
import com.ant.collect.handler.AntException;
import com.ant.collect.pojo.Company;
import com.ant.collect.pojo.User;
import com.ant.collect.service.ICompanyService;
import com.ant.collect.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hzd
 * @since 2025-10-23
 */
@Api(tags = "企业信息接口")
@RestController
@RequestMapping("/company")
public class CompanyController {

    @Autowired
    ICompanyService companysService;

    @Autowired
    IUserService userService;


    @ApiOperation(value = "获取企业列表")
    @GetMapping("/list")
    public ResultVo list() {
        return ResultVo.success("ok", companysService.list());
    }

    @ApiOperation(value = "保存企业信息")
    @PostMapping("/save")
    public ResultVo save(@RequestBody CompanyDto dto) {
        return ResultVo.success("添加成功", companysService.saveCompany(dto));
    }

    /**
     * 分页查询用户数据
     *
     * @param
     * @return
     */
    @GetMapping("/queryCompanyList")
    public ResultVo queryCompanyList(CompanyDto dto) {
        Map<String, Object> map = companysService.queryCompanyList(dto);
        return ResultVo.success(map);
    }

    @ApiOperation(value = "通过id获取详情")
    @GetMapping("/findCompanyById")
    public ResultVo findCompanyById(Integer id) {
        if(id==null){
            throw new AntException("请输入id");
        }
        Company company = companysService.getOne(new QueryWrapper<Company>().eq("id", id));
        company.setUser(userService.getOne(new QueryWrapper<User>().eq("id",company.getUserId())));
        return ResultVo.success("查询成功", company);
    }


    @ApiOperation(value = "企业审核通过")
    @GetMapping("/findApprovedById")
    public ResultVo findApprovedById(Integer id,Integer status) {
        if(id==null){
            throw new AntException("请输入id");
        }
         companysService.findApprovedById(id,status);
        return ResultVo.success("操作成功");
    }


}
